#include<bits/stdc++.h>
using namespace std;
int n;
vector<int> arr;
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    scanf("%d",&n);
    arr.resize(n+5);
    for(int i=0;i<n;i++){
        scanf("%d",&arr[i]);
    }
    int maxn=0;
    for(int i=0;i<1<<n;i++){
        int ans=0;
        vector<int> blue;
        vector<int> red;
        for(int j=0;j<n;j++){
            if((1<<j)&i) blue.push_back(arr[j]);
            else red.push_back(arr[j]);
        }
        for(int j=1;j<blue.size();j++){
            if(blue[j]==blue[j-1]) ans+=blue[j];
        }
        for(int j=1;j<red.size();j++){
            if(red[j]==red[j-1]) ans+=red[j];
        }
        maxn=max(maxn,ans);
    }
    printf("%d",maxn);
    return 0;
}
